﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using DevComponents.DotNetBar;

namespace HYWJ
{
    public partial class TXXZForm : Office2007Form
    {
        SqlCommand command = null;
        SqlDataReader dataReader = null;
        
        public TXXZForm()
        {
            InitializeComponent();
        }

        private void TXXZForm_Load(object sender, EventArgs e)
        {
            DataBase.OpenDataBase();
            string sql = "select SubjectName from Subject";
            command = new SqlCommand(sql, DataBase.connection);
            dataReader = command.ExecuteReader();
            if (!dataReader.HasRows)
            {
                MessageBox.Show("对不起,当前没有任何科目的试题!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            while (dataReader.Read())
            {
                cboSubjects.Items.Add(dataReader[0].ToString());
            }
            dataReader.Close();
            QuestionCls.ExamYesNo = true;
        }

        //选择题型
        private void btnStar_Click(object sender, EventArgs e)
        {
            if (cboSubjects.Text == "")
            {
                MessageBox.Show("请选择科目", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                try
                {
                    string sql = "select subjectId from subject where subjectName='" + cboSubjects.Text + "'";
                    command = new SqlCommand(sql, DataBase.connection);
                    dataReader = command.ExecuteReader();
                    if (dataReader.Read())
                    {
                        QuestionCls.StuSubjectId = (int)dataReader[0];
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                finally
                {
                    dataReader.Close();
                }
                QuestionCls.InitRnd(QuestionCls.StuSubjectId);
                examForm exf = new examForm();
                exf.Show();
                this.Close();
                
            }
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }



    }
}
